﻿namespace DA6502.CPU
{
    /// <summary>
    /// 6502 CPU 指令辞典。
    /// </summary>
    /// 这个文件在模拟器中没有用，只有在做反汇编等场合才会用到。
    public static class CommandDictionary
    {
        public static CommandCode[] CommandCodes = new CommandCode[]
        {
            new CommandCode("BRK",1, "产生一个软IRQ中断"),  // 00
            new CommandCode("ORA",2, "操作数与A进行OR运算，结果存入A"),  // 01
            new CommandCode("STP",1, "系统挂起"),  // 02
            new CommandCode("SLO",2, "操作数算术左移后与A进行OR运算，结果存入A"),  // 03
            new CommandCode("NOP",2, "空操作"),  // 04
            new CommandCode("ORA",2, "操作数与A进行OR运算，结果存入A"),  // 05
            new CommandCode("ASL",2, "算术左移"),  // 06
            new CommandCode("SLO",2, "操作数算术左移后与A进行OR运算，结果存入A"),  // 07
            new CommandCode("PHP",1, "压状态寄存器P入栈"),  // 08
            new CommandCode("ORA",2, "操作数与A进行OR运算，结果存入A"),  // 09
            new CommandCode("ASL",1, "算术左移"),  // 0A
            new CommandCode("ANC",2, "操作数与A进行或者运算，结果第7位存入进位标志C"),  // 0B
            new CommandCode("NOP",3, "空操作"),  // 0C
            new CommandCode("ORA",3, "操作数与A进行OR运算，结果存入A"),  // 0D
            new CommandCode("ASL",3, "算术左移"),  // 0E
            new CommandCode("SLO",3, "操作数算术左移后与A进行OR运算，结果存入A"),  // 0F
            new CommandCode("BPL",2, "N==0跳转"),  // 10
            new CommandCode("ORA",2, "操作数与A进行OR运算，结果存入A"),  // 11
            new CommandCode("STP",1, "系统挂起"),  // 12
            new CommandCode("SLO",2, "操作数算术左移后与A进行OR运算，结果存入A"),  // 13
            new CommandCode("NOP",2, "空操作"),  // 14
            new CommandCode("ORA",2, "操作数与A进行OR运算，结果存入A"),  // 15
            new CommandCode("ASL",2, "算术左移"),  // 16
            new CommandCode("SLO",2, "操作数算术左移后与A进行OR运算，结果存入A"),  // 17
            new CommandCode("CLC",1, "清进位标志C"),  // 18
            new CommandCode("ORA",3, "操作数与A进行OR运算，结果存入A"),  // 19
            new CommandCode("NOP",1, "空操作"),  // 1A
            new CommandCode("SLO",3, "操作数算术左移后与A进行OR运算，结果存入A"),  // 1B
            new CommandCode("NOP",3, "空操作"),  // 1C
            new CommandCode("ORA",3, "操作数与A进行OR运算，结果存入A"),  // 1D
            new CommandCode("ASL",3, "算术左移"),  // 1E
            new CommandCode("SLO",3, "操作数算术左移后与A进行OR运算，结果存入A"),  // 1F
            new CommandCode("JSR",3, "跳转至子程序 "),  // 20
            new CommandCode("AND",2, "操作数与A进行AND运算，结果存入A"),  // 21
            new CommandCode("STP",1, "系统挂起"),  // 22
            new CommandCode("RLA",2, "操作数循环左移后与A进行AND运算，结果存入A"),  // 23
            new CommandCode("BIT",2, "操作数与A进行AND运算，结果 第7位存入负标志位N，第6位存入溢出标志位V"),  // 24
            new CommandCode("AND",2, "操作数与A进行AND运算，结果存入A"),  // 25
            new CommandCode("ROL",2, "带进位标志位C的循环左移，"),  // 26
            new CommandCode("RLA",2, "操作数循环左移后与A进行AND运算，结果存入A"),  // 27
            new CommandCode("PLP",1, "弹状态寄存器P出栈"),  // 28
            new CommandCode("AND",2, "操作数与A进行AND运算，结果存入A"),  // 29
            new CommandCode("ROL",1, "带进位标志位C的循环左移，"),  // 2A
            new CommandCode("ANC",2, "操作数与A进行或者运算，结果第7位存入进位标志C"),  // 2B
            new CommandCode("BIT",3, "操作数与A进行AND运算，结果 第7位存入负标志位N，第6位存入溢出标志位V"),  // 2C
            new CommandCode("AND",3, "操作数与A进行AND运算，结果存入A"),  // 2D
            new CommandCode("ROL",3, "带进位标志位C的循环左移，"),  // 2E
            new CommandCode("RLA",3, "操作数循环左移后与A进行AND运算，结果存入A"),  // 2F
            new CommandCode("BMI",2, "N==1跳转"),  // 30
            new CommandCode("AND",2, "操作数与A进行AND运算，结果存入A"),  // 31
            new CommandCode("STP",1, "系统挂起"),  // 32
            new CommandCode("RLA",2, "操作数循环左移后与A进行AND运算，结果存入A"),  // 33
            new CommandCode("NOP",2, "空操作"),  // 34
            new CommandCode("AND",2, "操作数与A进行AND运算，结果存入A"),  // 35
            new CommandCode("ROL",2, "带进位标志位C的循环左移，"),  // 36
            new CommandCode("RLA",2, "操作数循环左移后与A进行AND运算，结果存入A"),  // 37
            new CommandCode("SEC",1, "置进位标志C"),  // 38
            new CommandCode("AND",3, "操作数与A进行AND运算，结果存入A"),  // 39
            new CommandCode("NOP",1, "空操作"),  // 3A
            new CommandCode("RLA",3, "操作数循环左移后与A进行AND运算，结果存入A"),  // 3B
            new CommandCode("NOP",3, "空操作"),  // 3C
            new CommandCode("AND",3, "操作数与A进行AND运算，结果存入A"),  // 3D
            new CommandCode("ROL",3, "带进位标志位C的循环左移，"),  // 3E
            new CommandCode("RLA",3, "操作数循环左移后与A进行AND运算，结果存入A"),  // 3F
            new CommandCode("RTI",1, "中断返回"),  // 40
            new CommandCode("EOR",2, "操作数与A进行EOR运算，结果存入A"),  // 41
            new CommandCode("STP",1, "系统挂起"),  // 42
            new CommandCode("SRE",2, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 43
            new CommandCode("NOP",2, "空操作"),  // 44
            new CommandCode("EOR",2, "操作数与A进行EOR运算，结果存入A"),  // 45
            new CommandCode("LSR",2, "算术右移"),  // 46
            new CommandCode("SRE",2, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 47
            new CommandCode("PHA",1, "压累加寄存器A入栈"),  // 48
            new CommandCode("EOR",2, "操作数与A进行EOR运算，结果存入A"),  // 49
            new CommandCode("LSR",1, "算术右移"),  // 4A
            new CommandCode("ALR",2, "操作数与A进行AND运算，结果算术右移，第0位存入进位标志位C"),  // 4B
            new CommandCode("JMP",3, "跳转"),  // 4C
            new CommandCode("EOR",3, "操作数与A进行EOR运算，结果存入A"),  // 4D
            new CommandCode("LSR",3, "算术右移"),  // 4E
            new CommandCode("SRE",3, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 4F
            new CommandCode("BVC",2, "V==0跳转"),  // 50
            new CommandCode("EOR",2, "操作数与A进行EOR运算，结果存入A"),  // 51
            new CommandCode("STP",1, "系统挂起"),  // 52
            new CommandCode("SRE",2, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 53
            new CommandCode("NOP",2, "空操作"),  // 54
            new CommandCode("EOR",2, "操作数与A进行EOR运算，结果存入A"),  // 55
            new CommandCode("LSR",2, "算术右移"),  // 56
            new CommandCode("SRE",2, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 57
            new CommandCode("CLI",1, "清中断标志位I"),  // 58
            new CommandCode("EOR",3, "操作数与A进行EOR运算，结果存入A"),  // 59
            new CommandCode("NOP",1, "空操作"),  // 5A
            new CommandCode("SRE",3, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 5B
            new CommandCode("NOP",3, "空操作"),  // 5C
            new CommandCode("EOR",3, "操作数与A进行EOR运算，结果存入A"),  // 5D
            new CommandCode("LSR",3, "算术右移"),  // 5E
            new CommandCode("SRE",3, "操作数算术右移后与A进行EOR运算，结果存入A"),  // 5F
            new CommandCode("RTS",1, "子程序返回"),  // 60
            new CommandCode("ADC",2, "操作数与A带进位相加，结果存入A及C"),  // 61
            new CommandCode("STP",1, "系统挂起"),  // 62
            new CommandCode("RRA",2, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 63
            new CommandCode("NOP",2, "空操作"),  // 64
            new CommandCode("ADC",2, "操作数与A带进位相加，结果存入A及C"),  // 65
            new CommandCode("ROR",2, "循环右移"),  // 66
            new CommandCode("RRA",2, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 67
            new CommandCode("PLA",1, "弹累加寄存器A出栈"),  // 68
            new CommandCode("ADC",2, "操作数与A带进位相加，结果存入A及C"),  // 69
            new CommandCode("ROR",1, "循环右移"),  // 6A
            new CommandCode("ARR",2, "操作数与A进行AND运算，结果循环右移"),  // 6B
            new CommandCode("JMP",3, "跳转"),  // 6C
            new CommandCode("ADC",3, "操作数与A带进位相加，结果存入A及C"),  // 6D
            new CommandCode("ROR",3, "循环右移"),  // 6E
            new CommandCode("RRA",3, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 6F
            new CommandCode("BVS",2, "V==1跳转"),  // 70
            new CommandCode("ADC",2, "操作数与A带进位相加，结果存入A及C"),  // 71
            new CommandCode("STP",1, "系统挂起"),  // 72
            new CommandCode("RRA",2, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 73
            new CommandCode("NOP",2, "空操作"),  // 74
            new CommandCode("ADC",2, "操作数与A带进位相加，结果存入A及C"),  // 75
            new CommandCode("ROR",2, "循环右移"),  // 76
            new CommandCode("RRA",2, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 77
            new CommandCode("SEI",1, "置中断标志位I"),  // 78
            new CommandCode("ADC",3, "操作数与A带进位相加，结果存入A及C"),  // 79
            new CommandCode("NOP",1, "空操作"),  // 7A
            new CommandCode("RRA",3, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 7B
            new CommandCode("NOP",3, "空操作"),  // 7C
            new CommandCode("ADC",3, "操作数与A带进位相加，结果存入A及C"),  // 7D
            new CommandCode("ROR",3, "循环右移"),  // 7E
            new CommandCode("RRA",3, "操作数循环右移后与A带进位相加，结果存入A及C"),  // 7F
            new CommandCode("NOP",2, "空操作"),  // 80
            new CommandCode("STA",2, "存累加寄存器A入内存"),  // 81
            new CommandCode("NOP",2, "空操作"),  // 82
            new CommandCode("SAX",2, "A与X进行AND，结果存入内存"),  // 83
            new CommandCode("STY",2, "存Y入内存"),  // 84
            new CommandCode("STA",2, "存累加寄存器A入内存"),  // 85
            new CommandCode("STX",2, "存X入内存"),  // 86
            new CommandCode("SAX",2, "A与X进行AND，结果存入内存"),  // 87
            new CommandCode("DEY",1, "Y--"),  // 88
            new CommandCode("NOP",2, "空操作"),  // 89
            new CommandCode("TXA",1, "X传入A"),  // 8A
            new CommandCode("XAA",2, "操作数与A与X进行AND，结果存入A"),  // 8B
            new CommandCode("STY",3, "存Y入内存"),  // 8C
            new CommandCode("STA",3, "存累加寄存器A入内存"),  // 8D
            new CommandCode("STX",3, "存X入内存"),  // 8E
            new CommandCode("SAX",3, "A与X进行AND，结果存入内存"),  // 8F
            new CommandCode("BCC",2, "C==0跳转"),  // 90
            new CommandCode("STA",2, "存累加寄存器A入内存"),  // 91
            new CommandCode("STP",1, "系统挂起"),  // 92
            new CommandCode("AHX",2, "A、X与（操作数指定地址的高字节+1）进行AND运算，结果存入内存"),  // 93
            new CommandCode("STY",2, "存Y入内存"),  // 94
            new CommandCode("STA",2, "存累加寄存器A入内存"),  // 95
            new CommandCode("STX",2, "存X入内存"),  // 96
            new CommandCode("SAX",2, "A与X进行AND，结果存入内存"),  // 97
            new CommandCode("TYA",1, "Y传入A"),  // 98
            new CommandCode("STA",3, "存累加寄存器A入内存"),  // 99
            new CommandCode("TXS",1, "X传入S"),  // 9A
            new CommandCode("TAS",3, "A与X进行AND，结果存入S；A、X与（操作数指定地址的高字节+1）进行AND运算，结果存入内存"),  // 9B
            new CommandCode("SHY",3, "Y与（操作数指定地址的高字节+1）进行AND运算，结果存入内存"),  // 9C
            new CommandCode("STA",3, "存累加寄存器A入内存"),  // 9D
            new CommandCode("SHX",3, "X与（操作数指定地址的高字节+1）进行AND运算，结果存入内存"),  // 9E
            new CommandCode("AHX",3, "A、X与（操作数指定地址的高字节+1）进行AND运算，结果存入内存"),  // 9F
            new CommandCode("LDY",2, "从内存中读Y"),  // A0
            new CommandCode("LDA",2, "从内存中读A"),  // A1
            new CommandCode("LDX",2, "从内存中读X"),  // A2
            new CommandCode("LAX",2, "从内存中读A、X"),  // A3
            new CommandCode("LDY",2, "从内存中读Y"),  // A4
            new CommandCode("LDA",2, "从内存中读A"),  // A5
            new CommandCode("LDX",2, "从内存中读X"),  // A6
            new CommandCode("LAX",2, "从内存中读A、X"),  // A7
            new CommandCode("TAY",1, "A传入Y"),  // A8
            new CommandCode("LDA",2, "从内存中读A"),  // A9
            new CommandCode("TAX",1, "A传入X"),  // AA
            new CommandCode("LAX",2, "从内存中读A、X"),  // AB
            new CommandCode("LDY",3, "从内存中读Y"),  // AC
            new CommandCode("LDA",3, "从内存中读A"),  // AD
            new CommandCode("LDX",3, "从内存中读X"),  // AE
            new CommandCode("LAX",3, "从内存中读A、X"),  // AF
            new CommandCode("BCS",2, "C==1跳转"),  // B0
            new CommandCode("LDA",2, "从内存中读A"),  // B1
            new CommandCode("STP",1, "系统挂起"),  // B2
            new CommandCode("LAX",2, "从内存中读A、X"),  // B3
            new CommandCode("LDY",2, "从内存中读Y"),  // B4
            new CommandCode("LDA",2, "从内存中读A"),  // B5
            new CommandCode("LDX",2, "从内存中读X"),  // B6
            new CommandCode("LAX",2, "从内存中读A、X"),  // B7
            new CommandCode("CLV",1, "清溢出标志位V"),  // B8
            new CommandCode("LDA",3, "从内存中读A"),  // B9
            new CommandCode("TSX",1, "S传入X"),  // BA
            new CommandCode("LAS",3, "操作数与S进行AND运算，结果存入A、X、S"),  // BB
            new CommandCode("LDY",3, "从内存中读Y"),  // BC
            new CommandCode("LDA",3, "从内存中读A"),  // BD
            new CommandCode("LDX",3, "从内存中读X"),  // BE
            new CommandCode("LAX",3, "从内存中读A、X"),  // BF
            new CommandCode("CPY",2, "Y-操作数，按结果设置各标志位"),  // C0
            new CommandCode("CMP",2, "A-操作数，按结果设置各标志位"),  // C1
            new CommandCode("NOP",2, "空操作"),  // C2
            new CommandCode("DCP",2, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // C3
            new CommandCode("CPY",2, "Y-操作数，按结果设置各标志位"),  // C4
            new CommandCode("CMP",2, "A-操作数，按结果设置各标志位"),  // C5
            new CommandCode("DEC",2, "操作数-1并存入内存"),  // C6
            new CommandCode("DCP",2, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // C7
            new CommandCode("INY",1, "Y++"),  // C8
            new CommandCode("CMP",2, "A-操作数，按结果设置各标志位"),  // C9
            new CommandCode("DEX",1, "X--"),  // CA
            new CommandCode("AXS",2, "A与X做AND运算，结果 -操作数，按运算结果设置各标志位"),  // CB
            new CommandCode("CPY",3, "Y-操作数，按结果设置各标志位"),  // CC
            new CommandCode("CMP",3, "A-操作数，按结果设置各标志位"),  // CD
            new CommandCode("DEC",3, "操作数-1并存入内存"),  // CE
            new CommandCode("DCP",3, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // CF
            new CommandCode("BNE",2, "Z==0跳转"),  // D0
            new CommandCode("CMP",2, "A-操作数，按结果设置各标志位"),  // D1
            new CommandCode("STP",1, "系统挂起"),  // D2
            new CommandCode("DCP",2, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // D3
            new CommandCode("NOP",2, "空操作"),  // D4
            new CommandCode("CMP",2, "A-操作数，按结果设置各标志位"),  // D5
            new CommandCode("DEC",2, "操作数-1并存入内存"),  // D6
            new CommandCode("DCP",2, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // D7
            new CommandCode("CLD",1, "清十进制标志位D"),  // D8
            new CommandCode("CMP",3, "A-操作数，按结果设置各标志位"),  // D9
            new CommandCode("NOP",1, "空操作"),  // DA
            new CommandCode("DCP",3, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // DB
            new CommandCode("NOP",3, "空操作"),  // DC
            new CommandCode("CMP",3, "A-操作数，按结果设置各标志位"),  // DD
            new CommandCode("DEC",3, "操作数-1并存入内存"),  // DE
            new CommandCode("DCP",3, "操作数--并存入内存，A-运算结果，按结果设置各标志位"),  // DF
            new CommandCode("CPX",2, "X-操作数，按结果设置各标志位"),  // E0
            new CommandCode("SBC",2, "带借位减法"),  // E1
            new CommandCode("NOP",2, "空操作"),  // E2
            new CommandCode("ISC",2, "操作数++，然后带借位减法"),  // E3
            new CommandCode("CPX",2, "X-操作数，按结果设置各标志位"),  // E4
            new CommandCode("SBC",2, "带借位减法"),  // E5
            new CommandCode("INC",2, "操作数++，结果存入内存"),  // E6
            new CommandCode("ISC",2, "操作数++，然后带借位减法"),  // E7
            new CommandCode("INX",1, "X++"),  // E8
            new CommandCode("SBC",2, "带借位减法"),  // E9
            new CommandCode("NOP",1, "空操作"),  // EA
            new CommandCode("SBC",2, "带借位减法"),  // EB
            new CommandCode("CPX",3, "X-操作数，按结果设置各标志位"),  // EC
            new CommandCode("SBC",3, "带借位减法"),  // ED
            new CommandCode("INC",3, "操作数++，结果存入内存"),  // EE
            new CommandCode("ISC",3, "操作数++，然后带借位减法"),  // EF
            new CommandCode("BEQ",2, "Z==1跳转"),  // F0
            new CommandCode("SBC",2, "带借位减法"),  // F1
            new CommandCode("STP",1, "系统挂起"),  // F2
            new CommandCode("ISC",2, "操作数++，然后带借位减法"),  // F3
            new CommandCode("NOP",2, "空操作"),  // F4
            new CommandCode("SBC",2, "带借位减法"),  // F5
            new CommandCode("INC",2, "操作数++，结果存入内存"),  // F6
            new CommandCode("ISC",2, "操作数++，然后带借位减法"),  // F7
            new CommandCode("SED",1, "置十进制标志位D"),  // F8
            new CommandCode("SBC",3, "带借位减法"),  // F9
            new CommandCode("NOP",1, "空操作"),  // FA
            new CommandCode("ISC",3, "操作数++，然后带借位减法"),  // FB
            new CommandCode("NOP",3, "空操作"),  // FC
            new CommandCode("SBC",3, "带借位减法"),  // FD
            new CommandCode("INC",3, "操作数++，结果存入内存"),  // FE
            new CommandCode("ISC",3, "操作数++，然后带借位减法"),  // FF
        };
    }

    public struct CommandCode
    {
        public string Command;
        public int Length;
        public string ToolTip;

        public CommandCode(string command, int length, string tip)
        {
            //  指令的汇编代码（三字节大写英文字母）
            Command = command;

            //  指令+操作数的长度（单位：字节）
            Length = length;

            ToolTip = tip;
        }

    }
}